package com.ccreservoirs;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ccreservoirs.entity.Item;

@Controller
public class HomeController {

	@RequestMapping("home")
	public String home() {
		System.out.println("index page");
		return "home";
	}

	@RequestMapping("datagrid")
	public String datagrid() {
		return "datagrid";
	}
	
	@RequestMapping("datagrid_client")
	public String datagridClient() {
		return "datagrid_client";
	}

	@RequestMapping("datagrid_data")
	@ResponseBody
	public List<Item> getdata() {
		List<Item> itemList = new ArrayList<Item>();

		Random random = new Random(1000);
		for (int i = 0; i < 100; i++) {
			Item item1 = new Item();

			item1.setItemid(i);
			item1.setProductid(random.nextInt(1000));
			item1.setListprice(random.nextDouble() + random.nextInt(1000));

			item1.setStatus(String.valueOf(random.nextBoolean()));
			item1.setUnitcost(random.nextDouble() + random.nextInt(1000));
			itemList.add(item1);

		}
		return itemList;
	}

}
